
use New1990-2004

keep if year == 1990
rename reporter country
rename product hs6 
keep country hs6 year S
sort country hs6
save new_1990, replace

use endowments_intensities_1990, clear
sort country hs6
merge country hs6 using new_1990
gen HK_dist = (HK_country - HK_prod)^2
gen  K_dist =  (K_country -  K_prod)^2
gen  T_dist =  (T_country -  T_prod)^2
gen dist = (HK_dist + K_dist + T_dist)^0.5 if S == 1
drop HK_dist K_dist T_dist _merge
keep if S == 1 & dist != .
save new_data, replace

foreach j of numlist 1991/2003 {
	use New1990-2004
	keep if year == `j'
	rename reporter country
	rename product hs6 
	keep country hs6 year S R
	sort country hs6
	save new_`j', replace
	
	use endowments_intensities_`j', clear
	sort country hs6
	merge country hs6 using new_`j'
	save new_`j'_data, replace
	gen HK_dist = (HK_country - HK_prod)^2
	gen  K_dist =  (K_country -  K_prod)^2
	gen  T_dist =  (T_country -  T_prod)^2
	gen dist = (HK_dist + K_dist + T_dist)^0.5 if S == 1
	drop HK_dist K_dist T_dist _merge
	keep if S == 1 & dist != .
	append using new_data
	save new_data, replace
}

use new_data, clear

replace R = 0 if R == .

* Table 6 column (2)

tab year, gen(t)
reg dist R t2-t14

